home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13621 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: jupiter.cs.uml.edu!jlee
  2. From: jlee@jupiter.cs.uml.edu (John Peter Lee)
  3. Newsgroups: comp.lang.c++
  4. Subject: when to inherit, when to compose...
  5. Date: 26 Mar 1996 15:56:41 GMT
  6. Organization: UMass-Lowell Computer Science
  7. Message-ID: <4j943p$7es@ulowell.uml.edu>
  8. NNTP-Posting-Host: jupiter.cs.uml.edu
  9.  
  10. Hi:
  11.  
  12.   I'm wondering about an OO design. Under what circumstances is it more
  13.   advantageous to use an inheritance hierarchy for a design, as opposed
  14.   to using object containment, and vice versa?
  15.  
  16.   With object containment: class "A" has a member class "B" declared
  17.   within it. A acts as a kindof handle class (I think) that forwards
  18.   requests to B, and handles B's output. 
  19.  
  20.   With inheritance: class "A" is a base class, and class "B" is a derived
  21.   class. Then A has virtual functions that are implemented in B. 
  22.  
  23.   -> Are there any general rules of thumb to apply here? Any literature?
  24.  
  25.   
  26.   The design I am currently developing involves classes that are graphical
  27.   in nature - they have a lot of Motif and graphics-related info. I want to
  28.   shield all of this graphics stuff from certain objects that interact with
  29.   these classes in a non-graphical way (I'm placing graphics descriptors
  30.   into a type of history structure, and doing a lot of manipulations of
  31.   these descriptors - actual graphics isn't required for any of this stuff).
  32.   I'm wondering whether or not to shield things via containment by having
  33.   a graphical class ptr as a member of the base class, or via inheritance by
  34.   having a subclass inherit the graphical stuff from a graphical base class.
  35.  
  36. thanks in advance - please reply directly to me.
  37.  
  38. jp
  39.  
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. JP Lee               Institute for Visualization and Perception Research
  42. jlee@cs.uml.edu                    University of Massachusetts at Lowell
  43. (508) 934-3384                  1 University Ave. Lowell, MA 01854
  44. (508) 452-4298 fax
  45.  
  46.               Don't accept cheap imitations !!!!
  47.  
  48.     Support H.R. 1500 - America's Redrock Wilderness Act !
  49.  
  50. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51.